package com.shoppingmall.activity.mine;

import android.text.InputType;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.example.zyh.toolslib.base.BaseActivity;
import com.example.zyh.toolslib.widget.TitleBar;
import com.shoppingmall.R;
import com.shoppingmall.utils.CommonUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 2020/3/12
 * 描述：修改密码
 */
public class ModifyPwdActivity extends BaseActivity {
    @BindView(R.id.title_bar)
    TitleBar titleBar;
    @BindView(R.id.et_old_pwd)
    EditText etOldPwd;
    @BindView(R.id.iv_see_old_pwd)
    ImageView ivSeeOldPwd;
    @BindView(R.id.et_new_pwd)
    EditText etNewPwd;
    @BindView(R.id.iv_see_new_pwd)
    ImageView ivSeeNewPwd;
    @BindView(R.id.et_re_new_pwd)
    EditText etReNewPwd;
    @BindView(R.id.iv_see_re_new_pwd)
    ImageView ivSeeReNewPwd;
    @BindView(R.id.tv_confirm_modify)
    TextView tvConfirmModify;

    private boolean oldPwdVisible, newPwdVisible, reNewPwdVisible;


    @Override
    protected int initLayout() {
        return R.layout.activity_mine_modify_password;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initEvent() {
        titleBar.setLeftLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }


    @OnClick({R.id.iv_see_old_pwd, R.id.iv_see_new_pwd, R.id.iv_see_re_new_pwd, R.id.tv_confirm_modify})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_see_old_pwd:
                if (oldPwdVisible) {
                    ivSeeOldPwd.setImageResource(R.mipmap.ic_eye_close);
                    etOldPwd.setTransformationMethod(PasswordTransformationMethod.getInstance());
                    oldPwdVisible = false;
                } else {
                    ivSeeOldPwd.setImageResource(R.mipmap.ic_eye_open);
                    etOldPwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
                    oldPwdVisible = true;
                }
                break;
            case R.id.iv_see_new_pwd:
                if (newPwdVisible) {
                    ivSeeNewPwd.setImageResource(R.mipmap.ic_eye_close);
                    newPwdVisible = false;
                    etNewPwd.setTransformationMethod(PasswordTransformationMethod.getInstance());
                } else {
                    ivSeeNewPwd.setImageResource(R.mipmap.ic_eye_open);
                    newPwdVisible = true;
                    etNewPwd.setTransformationMethod(PasswordTransformationMethod.getInstance());
                }
                break;
            case R.id.iv_see_re_new_pwd:
                if (reNewPwdVisible) {
                    ivSeeReNewPwd.setImageResource(R.mipmap.ic_eye_close);
                    reNewPwdVisible = false;
                    etReNewPwd.setTransformationMethod(PasswordTransformationMethod.getInstance());
                } else {
                    ivSeeReNewPwd.setImageResource(R.mipmap.ic_eye_open);
                    reNewPwdVisible = true;
                    etReNewPwd.setTransformationMethod(PasswordTransformationMethod.getInstance());
                }
                break;
            case R.id.tv_confirm_modify:
                String oldPwd = etOldPwd.getText().toString();
                String newPwd = etNewPwd.getText().toString();
                String reNewPwd = etReNewPwd.getText().toString();

                if (StringUtils.isEmpty(oldPwd) || StringUtils.isEmpty(newPwd)) {
                    ToastUtils.showShort("请输入密码");
                } else if (!StringUtils.equals(reNewPwd, newPwd)) {
                    ToastUtils.showShort("两次输入密码不一致");
                } else if (CommonUtils.matchPwd(etReNewPwd.getText().toString())) {

                } else {
                    ToastUtils.showShort("密码格式不正确");
                }
                break;
        }
    }
}
